package cn.k.service.impl;

import cn.k.domain.Department;
import cn.k.domain.Permission;
import cn.k.mapper.PermissionMapper;
import cn.k.qo.PageResult;
import cn.k.qo.QueryObject;
import cn.k.service.IPermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Service
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    @Transactional
    public void insert(Permission permission) {
         permissionMapper.insert(permission);
    }

    @Override
    public void delete(Long id) {
        permissionMapper.deleteByPrimaryKey(id);

    }

    @Override
    @Transactional
    public void update(Permission permission) {
        permissionMapper.updateByPrimaryKey(permission);

    }

    @Override
    public Permission get(Long id) {
        Permission permission = permissionMapper.selectByPrimaryKey(id);
        return permission;
    }

    @Override
    public List<Permission> selectAll() {
        List<Permission> permissions = permissionMapper.selectAll();
        return permissions;
    }



    @Override
    public List<Permission> selectForList(QueryObject qo) {
        List<Permission> permissions = permissionMapper.selectForList(qo);
        return permissions;
    }

    @Override
    public PageInfo<Permission> query(QueryObject qo) {
        //告诉插件我们查询第几页,每页多少条
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        //查询当前页数据
        List<Permission> permissions = permissionMapper.selectForList(qo);
        return new PageInfo<>(permissions);
    }

    @Override
    public void batchSave(Set<Permission> permissions) {
        permissionMapper.batchInsert(permissions);
    }

    @Override
    public List<Permission> queryByRoleId(Long roleId) {
        return permissionMapper.selectRoleById(roleId);
    }

    @Override
    public List<String> queryExpressionByEmployeeId(Long employeeId) {
        return permissionMapper.selectExpressionByEmployeeId(employeeId);
    }

    @Override
    public List<String> selectByEmpId(Long id) {
        return permissionMapper.selectByEmpId(id);
    }


}
